<template>
  <el-card class="admin-information-update" v-loading="loading">
    <tag-content-header setting :settingData="columns">
      <template #title>
        <span>标签信息批量更新</span>
      </template>
    </tag-content-header>
    <el-form inline :model="editForm" ref="editForm" label-width="100px">
      <el-row :gutter="20">
        <el-form-item prop="appPlfmNm" label="应用平台">
          <el-select v-model="editForm.appPlfmNm" filterable>
            <el-option label="---" value=""></el-option>
            <el-option
              v-for="item in plfmList"
              :key="item.appPlfmId"
              :label="item.appPlfmNm"
              :value="item.appPlfmId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="valueType" label="取值类型">
          <el-select v-model="editForm.valueType">
            <el-option label="---" value=""></el-option>
            <el-option
              v-for="item in $dictList('value_type')"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="tagKind" label="标签类别">
          <el-select v-model="editForm.tagKind">
            <el-option label="---" value=""></el-option>
            <el-option
              v-for="item in $dictList('tag_kind')"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="search">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="download(false)">导出</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="download(true)">导出全部</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="$refs.informationImportDrawer.showDrawer()">批量导入</el-button>
        </el-form-item>
      </el-row>
    </el-form>
    <tag-table ref="table" @refresh="getList" :data="dataList" :columns="columns" :params="params" :total="totalSize">
      <template #requirerNm="{ scope }">
        {{ $name(scope.row, 'requirerNnm', 'requirerNm') }}
      </template>
      <template #responserNm="{ scope }">
        {{ $name(scope.row, 'responserNnm', 'responserNm') }}
      </template>
      <template #amartDeveloperNm="{ scope }">
        {{ $name(scope.row, 'amartDeveloperNnm', 'amartDeveloperNm') }}
      </template>
      <template #bmartDeveloperNm="{ scope }">
        {{ $name(scope.row, 'bmartDeveloperNnm', 'bmartDeveloperNm') }}
      </template>
    </tag-table>
    <information-import-drawer ref="informationImportDrawer"></information-import-drawer>
  </el-card>
</template>

<script>
import informationImportDrawer from './information-import'
export default {
  components: {
    informationImportDrawer
  },
  data() {
    return {
      loading: false,
      plfmList: [],
      editForm: {
        appPlfmNm: '',
        valueType: '',
        tagKind: ''
      },
      dataList: [],
      columns: [
        {
          show: true,
          label: '标签名称',
          prop: 'tagNm',
          search: true,
          searchKey: ''
        },
        {
          show: true,
          label: '标签类别',
          prop: 'tagKind',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: true,
          label: '数据类型',
          prop: 'valueType',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: true,
          label: '统计粒度',
          prop: 'hqTag',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: false,
          label: '客户统计范围',
          prop: 'clientStatRange',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: false,
          label: '更新频率',
          prop: 'updateFreq',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: false,
          label: '更新规则',
          prop: 'updateFreqValue',
          align: 'center'
        },
        {
          show: true,
          label: '应用平台',
          prop: 'appPlfmNm',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: true,
          label: '数据平台',
          prop: 'dataPlfmNm',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: true,
          label: '数据库',
          prop: 'dbNm',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: true,
          label: '数据表',
          prop: 'tableNm',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: true,
          label: '数据字段',
          prop: 'fieldNm',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: false,
          label: '实际上线日期',
          prop: 'actRolloutDt',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: true,
          label: '提出人',
          prop: 'requirerNm',
          align: 'center'
        },
        {
          show: true,
          label: '负责团队',
          prop: 'respTeamNm',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: true,
          label: '负责人',
          prop: 'responserNm',
          align: 'center'
        },
        {
          show: false,
          label: '开发团队',
          prop: 'amartDevTeamNm',
          search: true,
          searchKey: '',
          align: 'center'
        },
        {
          show: false,
          label: '开发人',
          prop: 'amartDeveloperNm',
          align: 'center'
        }
      ],
      params: {
        ascs: [],
        descs: [],
        currentPageNum: 1,
        pageSize: 10,
        queryParams: {},
        descPriority: false
      },
      totalSize: 0
    }
  },
  created() {
    this.getPlfm()
    this.$nextTick(() => this.getList())
  },
  methods: {
    getPlfm() {
      this.$ajax({
        url: this.$ajax.setUrl('ast/astAppPlatform/getAll'),
        method: 'get',
        params: this.$ajax.setParams()
      }).then(({ data }) => {
        if (data && data.code === '0') {
          this.plfmList = data.data
        } else {
          this.$message.error(data.data || data.msg)
        }
      })
    },
    search() {
      this.params = {
        ascs: [],
        descs: [],
        currentPageNum: 1,
        pageSize: 10,
        queryParams: {},
        descPriority: false
      }
      this.getList()
    },
    getList() {
      this.$refs.editForm.validate(valid => {
        if (valid) {
          if (this.editForm.appPlfmNm) this.params.queryParams.appPlfmNm = this.editForm.appPlfmNm
          if (this.editForm.valueType) this.params.queryParams.valueType = this.editForm.valueType
          if (this.editForm.tagKind) this.params.queryParams.tagKind = this.editForm.tagKind
          this.loading = true
          this.$ajax({
            url: this.$ajax.setUrl('auth/admin/tagInfoList'),
            method: 'get',
            params: this.$ajax.setParams(this.params)
          }).then(({ data }) => {
            if (data && data.code === '0') {
              this.dataList = data.data.records
              this.totalSize = data.data.totalSize
            } else {
              this.$message.error(data.data || data.msg)
            }
            this.loading = false
          })
        }
      })
    },
    download(isAll = false) {
      this.$refs.editForm.validate(valid => {
        if (valid) {
          this.loading = true
          let param = {}
          if (!isAll) {
            if (this.editForm.appPlfmNm) param.appPlfmNm = this.editForm.appPlfmNm
            if (this.editForm.valueType) param.valueType = this.editForm.valueType
            if (this.editForm.tagKind) param.tagKind = this.editForm.tagKind
          }
          this.$ajax({
            url: this.$ajax.setUrl('auth/admin/downloadTagInfo'),
            method: 'post',
            data: this.$ajax.setData(param)
          }).then(({ data }) => {
            if (data && data.code === '0') {
              this.$dlFile(data.data)
              this.$message.success(data.msg)
            } else {
              this.$message.error(data.data || data.msg)
            }
            this.loading = false
          })
        }
      })
    }
  }
}
</script>

<style lang="scss">
.admin-information-update {
  .tag-content-header .content-tools {
    position: relative;
    top: 55px;
    z-index: 2;
  }
  .el-button {
    margin-left: 20px;
  }
  .tag-table {
    margin-top: -10px;
  }
}
</style>
